#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@file config_manager.py
@author weiximei
@date 2025/3/5 15:25
"""
from typing import Optional

from config.app import AppConfig
from internal.common import config


class ConfigManager:
    """配置管理器"""

    _instance: Optional['ConfigManager'] = None
    _config: Optional[AppConfig] = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance

    def init_config(self, env: str):
        """初始化配置"""
        if self._config is None:
            self._config = config.load_config(env)

    @property
    def config(self) -> AppConfig:
        """获取配置"""
        if self._config is None:
            raise RuntimeError("配置未初始化，请先调用 init_config")
        return self._config


# 全局配置管理器实例
config_manager = ConfigManager()
